package com.kefu.notice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kefu.common.controller.AbstractBaseController;
import com.kefu.common.result.Result;
import com.kefu.common.result.ResultGenerator;
import com.kefu.common.vo.DeleteVo;
import com.kefu.common.vo.DetailVo;
import com.kefu.notice.model.BossNoticeInfo;
import com.kefu.notice.service.BossNoticeInfoService;
import com.kefu.notice.vo.BossNoticeInfoSearchVo;
import com.kefu.notice.vo.BossNoticeInfoInsertVo;
import com.kefu.notice.vo.BossNoticeInfoUpdateVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@Api(tags = "")
@RequestMapping("notice/info")
public class BossNoticeInfoController extends AbstractBaseController {

    @Autowired
    private BossNoticeInfoService bossNoticeInfoService;

    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public Result<String> add(@Validated @RequestBody BossNoticeInfoInsertVo bossNoticeInfoVo) {
    	logger.info("新增:{}", bossNoticeInfoVo);
    	
    	BossNoticeInfo info = bossNoticeInfoVo.convert();
        bossNoticeInfoService.save(info);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public Result<String> delete(@Validated @RequestBody DeleteVo delete) {
    	logger.info("删除:{}", delete);
    	
        bossNoticeInfoService.removeById(delete.getId());
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public Result<String> update(@Validated @RequestBody BossNoticeInfoUpdateVo bossNoticeInfoVo) {
    	logger.info("修改:{}", bossNoticeInfoVo);
    	
        bossNoticeInfoService.updateNotice(bossNoticeInfoVo);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    @ApiOperation(value = "详情")
    public Result<BossNoticeInfo> detail(@Validated @RequestBody DetailVo detail) {

        BossNoticeInfo bossNoticeInfo = bossNoticeInfoService.getById(detail.getId());
        return ResultGenerator.genSuccessResult(bossNoticeInfo);
    }
    @PostMapping("/publish")
    @ApiOperation(value = "发布")
    public Result<BossNoticeInfo> publish(@Validated @RequestBody DetailVo detail) {
    	
    	BossNoticeInfo bossNoticeInfo = bossNoticeInfoService.publish(detail.getId());
    	return ResultGenerator.genSuccessResult(bossNoticeInfo);
    }
    @PostMapping("/revoke")
    @ApiOperation(value = "撤回")
    public Result<BossNoticeInfo> revoke(@Validated @RequestBody DetailVo detail) {
    	
    	BossNoticeInfo bossNoticeInfo = bossNoticeInfoService.revoke(detail.getId());
    	return ResultGenerator.genSuccessResult(bossNoticeInfo);
    }
    
    @PostMapping("/enable")
    @ApiOperation(value = "启用")
    public Result<BossNoticeInfo> enable(@Validated @RequestBody DetailVo detail) {
    	
    	BossNoticeInfo bossNoticeInfo = bossNoticeInfoService.enable(detail.getId());
    	return ResultGenerator.genSuccessResult(bossNoticeInfo);
    }
    
    @PostMapping("/disabled")
    @ApiOperation(value = "禁用")
    public Result<BossNoticeInfo> disabled(@Validated @RequestBody DetailVo detail) {
    	
    	BossNoticeInfo bossNoticeInfo = bossNoticeInfoService.disabled(detail.getId());
    	return ResultGenerator.genSuccessResult(bossNoticeInfo);
    }
    @PostMapping("/down")
    @ApiOperation(value = "向下")
    public Result<String> down(@Validated @RequestBody DetailVo detail) {
    	
    	bossNoticeInfoService.down(detail.getId());
    	return ResultGenerator.genSuccessResult();
    }
    @PostMapping("/up")
    @ApiOperation(value = "向上")
    public Result<String> up(@Validated @RequestBody DetailVo detail) {
    	
    	bossNoticeInfoService.up(detail.getId());
    	return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询")
    public Result<Page<BossNoticeInfo>> list(@Validated @RequestBody BossNoticeInfoSearchVo search) {    

        Page<BossNoticeInfo> page = bossNoticeInfoService.searchLambdaPage(search);
        return ResultGenerator.genSuccessResult(page);
    }
}
